/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.personal.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import lombok.AllArgsConstructor;
import javax.validation.Valid;

import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.system.service.IUserService;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.modules.personal.entity.UserBaseEntity;
import org.springblade.modules.personal.vo.UserBaseVO;
import org.springblade.modules.personal.wrapper.UserBaseWrapper;
import org.springblade.modules.personal.service.IUserBaseService;
import org.springblade.core.boot.ctrl.BladeController;

/**
 * 基本用户字段 控制器
 *
 * @author BladeX
 * @since 2023-03-22
 */
@RestController
@AllArgsConstructor
@RequestMapping("blade-userBase/userBase")
@Api(value = "基本用户信息", tags = "基本用户信息接口")
public class UserBaseController extends BladeController {

	private final IUserBaseService userBaseService;
	private final IUserService userService;

	/**
	 * 基本用户字段 详情
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "传入userBase")
	public R<UserBaseVO> detail(UserBaseEntity userBase) {
		UserBaseEntity detail = userBaseService.getOne(Condition.getQueryWrapper(userBase));
		return R.data(UserBaseWrapper.build().entityVO(detail));
	}

	/**
	 * 基本用户字段 分页
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入userBase")
	public R<IPage<UserBaseVO>> list(UserBaseEntity userBase, Query query) {
		IPage<UserBaseEntity> pages = userBaseService.page(Condition.getPage(query), Condition.getQueryWrapper(userBase));
		return R.data(UserBaseWrapper.build().pageVO(pages));
	}

	/**
	 * 基本用户字段 自定义分页
	 */
	@GetMapping("/page")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "分页", notes = "传入userBase")
	public R<IPage<UserBaseVO>> page(UserBaseVO userBase, Query query) {
		IPage<UserBaseVO> pages = userBaseService.selectUserBasePage(Condition.getPage(query), userBase);
		return R.data(pages);
	}

	/**
	 * 基本用户字段 新增
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "新增", notes = "传入userBase")
	public R save(@Valid @RequestBody UserBaseEntity userBase) {
		return R.status(userBaseService.save(userBase));
	}

	/**
	 * 基本用户字段 修改
	 */
	@PostMapping("/update")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "修改", notes = "传入userBase")
	public R update(@Valid @RequestBody UserBaseEntity userBase) {
		return R.status(userBaseService.updateById(userBase));
	}


	/**
	 * 基本用户字段 删除
	 */
	@PostMapping("/remove")
	@ApiOperationSupport(order = 7)
	@ApiOperation(value = "逻辑删除", notes = "传入ids")
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.status(userBaseService.deleteLogic(Func.toLongList(ids)));
	}


	/**
	 * 获取学员信息
	 * 用于绑定班级的
	 */
	@PostMapping("/get-student")
	@ApiOperationSupport(order = 8)
	@ApiOperation(value = "获取学员信息", notes = "获取学员信息")
	public R getStudent(UserBaseVO userBase, Query query) {
		IPage<UserBaseVO> pages = userBaseService.selectUserPage(Condition.getPage(query), userBase);
		return R.data(pages);
	}

	/**
	 * 获取考试学员的信息
	 * 用于绑定考试的(考试与学员绑定)
	 */
	@PostMapping("/get-exam-student")
	@ApiOperationSupport(order = 9)
	@ApiOperation(value = "获取考试学员的信息", notes = "获取考试学员的信息")
	public R getExamStudent(UserBaseVO userBase, Query query) {
		//TODO 此处的搜索待接入
		IPage<UserBaseVO> pages = userBaseService.selectUserPage(Condition.getPage(query), userBase);
		return R.data(pages);
	}



	/**
	 * 用户个人信息
	 */
	@GetMapping("/info")
	@ApiOperationSupport(order = 15)
	@ApiOperation(value = "用户个人信息", notes = "")
	public R info() {
		return R.data(userBaseService.getUserInfo(AuthUtil.getUserId()));
	}
}
